$(function () {
    $.ajax({
        url: baseloaction + '/mobile/index/getIndexPopupSlogan',
        type: 'post',
        dataType: 'json',
        async: false,
        data: {},
        success: function (result) {
            if (result.success == true) {
                var obj = result.entity;
                var imagUrl = obj.imag;
                var id = obj.popupSloganDetailId;
                var type = obj.chainedType;
                var url = obj.chained;
                diglog_mobile(imagUrl, id, type, url);
            }
        }
    });
})

//弹窗广告
function diglog_mobile(imagUrl, id, type, url) {
    var adsUrl = imagUrl;
    timer = null,
        _body = document.querySelector('body'),
        _ele = '';
    _ele += '<div class="modal-overlay modal-overlay-visible"></div>';
    _ele += '<div class="ads-modal__wrap"><div class="ads-modal-box pr"><img id="ads-img-ele" src="' + adsUrl + '" style="max-width: 600px;max-height: 800px"><span class="ads-modal-closeBtn"></span></div></div>';

    var _dEle = document.createElement("div");
    _dEle.id = 'modal-overlay__wrap';
    _dEle.innerHTML = _ele;

    function adsModalFn() {
        clearTimeout(timer);
        timer = setTimeout(function () {
            _body.appendChild(_dEle);
            $('body').on('click', '#ads-img-ele', function () {  //点击广告图时
                if ('1' == type) {
                    addClick(id);
                    window.location.href = url;
                } else if ('2' == type) {
                    //2、设置三方客服时
                    addClick(id);
                    window.open(url, 'newwindow', 'toolbar=no,scrollbars=yes,location=no,resizable=no,top=200,left=300,width=800,height=600');
                }
            });

        }, 1500);
        $('body').on('click', '.ads-modal-closeBtn', function () {  //点击关闭时
            $('#modal-overlay__wrap').remove();
        })
    }
    adsModalFn();
}

function addClick(id) {
    $('#modal-overlay__wrap').remove();
    $.ajax({
        url:baseloaction +'/mobile/index/addClick',
        type:'post',
        dataType:'json',
        async:false,
        data:{"id":id},
        success: function (result) {
        }
    });
}